package com.hualan.servlet;

import com.alibaba.fastjson.JSON;
import com.hualan.bean.PanghuCommunity;
import com.hualan.dao.CommunityDao;
import com.hualan.dao.CommunityDaoImpl;
import com.hualan.dao.GeneralResult;
import com.hualan.dao.PageResult;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;

@WebServlet("/community/communityList")
public class CommunityListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {



        //接收参数  name=1&startTime=2024-06-24+00:00:00&
        // endTime=2024-06-24+00:00:00&pageNum=1&pageSize=10&communityName=


        String name = req.getParameter("name");
        String startTime = req.getParameter("startTime");
        String endTime = req.getParameter("endTime");
        String pageNum = req.getParameter("pageNum");
        String pageSize = req.getParameter("pageSize");
        String communityName = req.getParameter("communityName");
        HashMap<String,Object> map = new HashMap<>();
        CommunityDao communityDao = new CommunityDaoImpl();
        List<PanghuCommunity> communityList = communityDao.AllCommunity(name,startTime,endTime,pageNum,pageSize,communityName);
        map.put("list",communityList);

        if ( communityList != null){
            map.put("code",200);
            map.put("message","请求成功");
        }else {
            map.put("code",300);
            map.put("message","获取数据失败");
        }
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String jsonString = JSON.toJSONString(map);
        resp.getWriter().write(jsonString);


    }
}

